import Dl from '@/views/login/dl.vue'
import Fl from '@/views/login/fl.vue'
import Gwc from '@/views/login/gwc.vue'
import Login from '@/views/login/login.vue'
import My from '@/views/login/my.vue'
import Sy from '@/views/login/sy.vue'
import Zc from '@/views/login/zc.vue'
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: Login,
      children: [
        {
          path: 'sy',
          component: Sy,
        },
        {
          path: 'fl',
          component: Fl,
        },
        {
          path: 'gwc',
          component: Gwc,
        },
        {
          path: 'my',
          component: My,
        },
      ]
    },
    {
      path: '/dl',
      component: Dl,
    },
    {
      path: '/zc',
      component: Zc,
    },
  ],
})
router.beforeEach((to, from, next) => {
  if (to.fullPath == '/login/gwc' || to.fullPath == '/login/my') {
    let token = localStorage.getItem('token')
    if (token) {
      next()
    } else {
      next('/zc')
    }
  } else {
    next()
  }
})
export default router
